﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UserModule
{
    public static class UserManager
    {
        static public string strCurrentUser;
        static public int iUserLevel = 0;
        static public UserSetting userSetting;
        static public DevExpress.XtraBars.BarStaticItem userStaticItem;
        public static void Init(DevExpress.XtraBars.BarStaticItem  userStatic)
        {
            userStaticItem = userStatic;
            userSetting = UserSetting.Load();
            iUserLevel = 0;


            FrameManager.FrameManager.saveProject += FrameManager_saveProject;



            if (userSetting.strOperatorPW == "")
            {
                iUserLevel = 0;
                userStaticItem.Caption = "NoUser-Operator";
                return;
            }
            if (userSetting.strCodePW == "")
            {
                iUserLevel = 4;
                userStaticItem.Caption = "NoUser-Designer";
                return;
            }
            if (userSetting.strAdministatorPW == "")
            {
                iUserLevel = 3;
                userStaticItem.Caption = "NoUser-Admini";
                return;
            }
            if (userSetting.strEngineerPW == "")
            {
                iUserLevel = 2;
                userStaticItem.Caption = "NoUser-Engineer";
                return;
            }
            if (userSetting.strTechPW == "")
            {
                iUserLevel = 1;
                userStaticItem.Caption = "NoUser-Tech";
                return;
            }
            
            FormUserLogoIn frmUserLogIn = new FormUserLogoIn();
            frmUserLogIn.ShowDialog();
        }
        private static bool FrameManager_saveAsProject()
        {

            return true;
        }

        private static bool FrameManager_saveProject()
        {
            userSetting.Save();
            return true;
        }

        private static bool FrameManager_openProject()
        {
            return true;
        }

        private static bool FrameManager_newProject()
        {
            return true;
        }
        public static bool LogIn(string pwd)
        {
            if (pwd=="")
            {
                UserManager.userStaticItem.Caption = "_" + "Operator";
                UserManager.iUserLevel = 0;
                return true;
            }
            if (pwd == userSetting.strOperatorPW)
            {
                UserManager.userStaticItem.Caption = "_" + "Operator";
                UserManager.iUserLevel = 0;
                return true;
            }
            if (pwd == userSetting.strTechPW)
            {
                UserManager.userStaticItem.Caption = "_" + "Tech";
                UserManager.iUserLevel = 1;
                return true;
            }
            if (pwd == userSetting.strEngineerPW)
            {
                UserManager.userStaticItem.Caption =  "_" + "Engineer";
                UserManager.iUserLevel = 2;
                return true;
            }
            if (pwd == userSetting.strAdministatorPW)
            {
                UserManager.userStaticItem.Caption = "_" + "Administator";
                UserManager.iUserLevel = 3;
                return true;
            }
            if (pwd == userSetting.strCodePW)
            {
                UserManager.userStaticItem.Caption = "_" + "Designer";
                UserManager.iUserLevel = 4;
                return true;
            }
            return false;
        }
    }
}
